import { creepConfigs } from "./creepConfigs";
const addCreep = (spawn: StructureSpawn) => {
  const creepList = Object.values(Game.creeps);
  for (const creepConfig of creepConfigs) {
    const creepRoleList = creepList.filter((item) => item.memory.role === creepConfig.role);
    if (creepRoleList.length < creepConfig.number) {
      for (let index = 0; index < creepConfig.number; index++) {
        if (Game.creeps[creepConfig.role + index] === undefined) {
          const code = spawn.spawnCreep(creepConfig.bodys, creepConfig.role + index, {
            memory: { role: creepConfig.role },
          });
          console.log("错误code=" + code);
          return code;
        }
      }
    }
  }
};

export const autoAddCreep = () => {
  for (const name in Game.spawns) {
    const spawn = Game.spawns[name];
    if (spawn.spawning === null && spawn.store.getUsedCapacity(RESOURCE_ENERGY) >= 300) {
      addCreep(spawn);
    }
  }
};
